

import java.util.Properties;

import c4.application.transactions.AccountRepresentation;
import c4.application.transactions.Task;
import c4.application.transactions.TransactionManager;
import c4.application.transactions.Worker;
import c4.common.Constants;

/**
 * A sample GUI class that demonstrates how to interact with the
 * Transaction Manager. 
 *
 * @author David Strickland
 */
public class GUI {
	Properties display; //all of these will map to Swing objects being displayed

	public GUI() {
		//Initial load of all Swing object values 
		loadDisplay();
		
		//Display all of the Swing values
		display.list(System.out);
		System.out.println("\n-----------\n");
		
		//Interact with Transaction Manager
		Worker worker; //remote object
		TransactionManager manager; //remote object
		Task task;
		AccountRepresentation representation;
		try{
		manager = new TransactionManager();
		
		worker = manager.getWorker();

		//Customer Login Task
		task = new Task(Constants.CUSTOMER_LOGIN);
		task.addParameter(Constants.PIN, "5791");
		task.addParameter(Constants.ACCOUNT_NUMBER, "1");
		
		representation = worker.request(task);
		
		if (representation.getSuccessful()) { //everything was Ok, so display
			display.putAll(representation.getUpdates()); //load all updated values
			display.list(System.out); //display with updates
		}
			
		else //there was an error with the request, so errors should be displayed
			System.out.println(representation.getErrorMessages()); //display error
		}catch(Exception e){}
	}

	/**
	 * Initialize all of the values that will be displayed by Swing objects
	 */
	private void loadDisplay() {
		display = new Properties();
		
		display.setProperty(Constants.PIN, "");
		display.setProperty(Constants.NAME, "");
		display.setProperty(Constants.DOB, "");
		display.setProperty(Constants.SSN, "");
		display.setProperty(Constants.STREET, "");
		display.setProperty(Constants.ZIP, "");
		display.setProperty(Constants.CITY, "");
		display.setProperty(Constants.STATE, "");
		display.setProperty(Constants.VOICEMAIL, "");
		display.setProperty(Constants.CALLER_ID, "");
		display.setProperty(Constants.THREE_WAY, "");
		display.setProperty(Constants.DISTANCE_PROVIDER, "");
		display.setProperty(Constants.ACCOUNT_NUMBER, "");
		display.setProperty(Constants.PHONE0, "");
		display.setProperty(Constants.PHONE1, "");
		display.setProperty(Constants.PHONE2, "");
		display.setProperty(Constants.PHONE3, "");
		
		display.setProperty(Constants.TROUBLE0, "");
		display.setProperty(Constants.TROUBLE1, "");
		display.setProperty(Constants.TROUBLE2, "");
		display.setProperty(Constants.TROUBLE3, "");
		
		display.setProperty(Constants.SERVICE0, "");
		display.setProperty(Constants.SERVICE1, "");
		display.setProperty(Constants.SERVICE2, "");
		display.setProperty(Constants.SERVICE3, "");
		
	}
	
	/**
	 * Main
	 */
	public static void main(String[] args){
		GUI gui = new GUI();
	}

}
